import { baseUrlApi, requestClient, type Result } from '#/api/request';

/** 获取插件列表 */
export const getPlugins = (params?: object) => {
  return requestClient.get<Result>(baseUrlApi('/admin/plugins'), { params });
};

/** 获取插件配置 */
export const getPluginConfig = (params: { id: number }) => {
  return requestClient.get<Result>(
    baseUrlApi(`/admin/plugins/${params.id}/config`),
  );
};

/** 插件钩子 */
export const getPluginHooks = (id: number) => {
  return requestClient.get<Result>(baseUrlApi(`/admin/plugins/hooks/${id}`));
};

/** 插件配置提交保存 */
export const putPluginConfig = (data: { config: any; id: number }) => {
  return requestClient.put<Result>(
    baseUrlApi(`/admin/plugins/${data.id}/config`),
    data,
  );
};

/** 更新插件 */
export const putPlugin = (data: { name: string }) => {
  return requestClient.put<Result>(
    baseUrlApi(`/admin/plugins/${data.name}`),
    data,
  );
};

/** 安装插件 */
export const postPlugin = (data: { name: string }) => {
  return requestClient.post<Result>(
    baseUrlApi(`/admin/plugins/${data.name}`),
    data,
  );
};

/** 卸载插件 */
export const deletePlugin = (id: number) => {
  return requestClient.delete<Result>(baseUrlApi(`/admin/plugins/${id}`));
};

/** 设置插件启用状态 */
export const postPluginStatus = (data: { id: number; status: number }) => {
  return requestClient.post<Result>(
    baseUrlApi(`/admin/plugins/${data.id}/status/${data.status}`),
    data,
  );
};
